home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / 3d & render tools / irit / contrib / cagd / bspline / widgets.irt < prev   
Encoding:
Text File  |  1996-07-16  |  4.6 KB  |  151 lines

  1. #
  2. # Demonstration Tools
  3. #
  4. #
  5. # TODO:
  6. #    make code for creating different bars reusable
  7.  
  8. ###############################################################################
  9. #  Thumb Attachements
  10. ###############################################################################
  11.  
  12. CreateThumb = FUNCTION(vect):
  13.     return = sphereSrf(0.025) * trans(vect);
  14.  
  15. CreateAnimThumb = FUNCTION(curve): thumb: pt: cent: mov_xyz: visible:
  16.     pt = ceval(curve, 0):
  17.     cent = vector(coord(pt, 1) ,coord(pt, 2), 0):
  18.     thumb = CreateThumb(cent):
  19.     mov_xyz = curve*trans(-cent):
  20.     visible = ctlpt(E1, 0) + ctlpt(E1, 10):
  21.     attrib(thumb, "animation", list(mov_xyz, visible)):
  22.     return = thumb;
  23.  
  24. AttachThumbToCurve = FUNCTION(curve): 
  25.     return = list(curve, CreateAnimThumb(curve));
  26.  
  27. AttachNodesToCtlpoly = FUNCTION(plgn, colors): obj: i:
  28.     return = list(plgn):
  29.     for (i=1, 1, sizeof(plgn),
  30.         obj = CreateThumb(coerce(coord(plgn, i-1), VECTOR_TYPE)):
  31.         color(obj, nth(colors, i)):
  32.         snoc(obj, return)
  33.     );    
  34.  
  35. ###############################################################################
  36. #  Parametric Domain Knot Bar
  37. ###############################################################################
  38.  
  39. KnotVectorPlacement = FUNCTION(knotVector): xlen: delta: i: klist: x: y:
  40.     # Returns:
  41.     #    list of horizontal placements for the knot vector values in IRIT
  42.     #    bspline demo 'domain area'.
  43.  
  44.     x = 0.6:
  45.     y = -0.7:
  46.     xlen = sizeof(knotVector):
  47.     klist = nil():
  48.     delta = nth(knotVector, xlen) - nth(knotVector,1):
  49.     for (i=1, 1, xlen,
  50.         snoc((nth(knotVector,i)-nth(knotVector,1)) / delta, klist)
  51.     ):
  52.     return = list(vector(-x, y, 0)):
  53.     for (i=2, 1, xlen,
  54.         delta = 2*x*(nth(klist, i) - 0.5):  # x = -x0 + dx*(t-t0)/dt
  55.         if (nth(klist, i) == nth(klist, i-1),
  56.             snoc(vector(delta, coord(nth(return, i-1), 1)-0.04, 0), return),
  57.             snoc(vector(delta, y, 0), return)
  58.         )
  59.     );
  60.  
  61. KnotVectorBar = FUNCTION(order, knotVector):
  62.     # Returns:
  63.     #    list of object representing knot vector domain bar, placed horizontally
  64.     #    and aligned in IRIT Bspline Demo 'domain area',    with knots positions
  65.     #    marked by cones, placed under domain bar. Multiple notes are taken care
  66.     #    by stacking one under another. Colors are used to distinguish bspline 
  67.     #    curve domain.
  68.  
  69.     xlen: places: xl: xr: y: l1: l2: step: i: tri: bar: thumb: mov_xyz:
  70.     
  71.     xlen = sizeof(knotVector):
  72.     places = KnotVectorPlacement(knotVector): 
  73.     xl = coord(nth(places, 1), 0):
  74.     xr = coord(nth(places, xlen), 0):
  75.     y  = coord(nth(places, 1), 1):
  76.  
  77.     # Create bar line
  78.  
  79.     bar = ctlpt(E2, xl, y) + ctlpt(E2, xr, y):
  80.     color(bar, white):
  81.     return = list(bar):
  82.  
  83.     # Create large tick marks
  84.  
  85.     l1 = ctlpt(E2, xl, y - 0.025) + ctlpt(E2, xl, y + 0.025):
  86.     color(l1, white):
  87.     snoc(l1, return):
  88.     snoc(l1 * tx(xr-xl), return):
  89.  
  90.     # Create small tick marks
  91.  
  92.     step = (xr - xl) / (xlen - 1):
  93.     l2 = ctlpt(E2, xl, y - 0.015) + ctlpt(E2, xl, y + 0.015):
  94.     color(l2, white):
  95.     for (i=0, 1, xlen-1, snoc(l2 * tx(i*step), return)):
  96.  
  97.     # Create knot vector representation
  98.  
  99.     tri = coneSrf(0.04, 0.02) * (rotx(-90) * ty(-0.07)):
  100.     color(tri, white): # grey color
  101.     for (i=1, 1, order-1, snoc(tri*trans(nth(places, i)), return)):
  102.     color(tri, yellow):
  103.     for (i=order, 1, xlen-order+1, snoc(tri*trans(nth(places, i)), return)):
  104.     color(tri, white): 
  105.     for (i=xlen-order+2, 1, xlen, snoc(tri*trans(nth(places, i)), return));
  106.  
  107.  
  108. KnotVectorBarWithThumb = FUNCTION(order, knotVector, t):
  109.     # Requires:
  110.     #    t is insode knotVector domain.
  111.     # Returns:
  112.     #    list of objects from knot vector bar and thumb object at 't'.
  113.  
  114.     places: xlen: xl: xr: tl: tr: thumb:
  115.     places = KnotVectorPlacement(knotVector):
  116.     xlen = sizeof(knotVector):
  117.     xl = coord(nth(places, 1), 0):
  118.     xr = coord(nth(places, xlen), 0):
  119.     tl = nth(knotVector, 1):
  120.     tr = nth(knotVector, xlen):
  121.     xl = xl + (t - tl) * (xr - xl) / (tr - tl):
  122.     return = KnotVectorBar(order, knotVector):
  123.     thumb = CreateThumb(vector(xl, coord(nth(places, 1), 1), 0)):
  124.     color(thumb, white):
  125.     snoc(thumb, return);
  126.  
  127.  
  128. KnotVectorBarAnimThumb = FUNCTION(knotVector, ind1, ind2): places: l: r: crv:
  129.     # Returns:
  130.     #    thumb with animation curve from 'knotVector[ind1]' to 'knotVector[ind2]'
  131.  
  132.     places = KnotVectorPlacement(knotVector):
  133.     l = nth(places, ind1):
  134.     r = nth(places, ind2):
  135.     crv = ctlpt(E2, coord(l, 0), coord(l, 1)) + ctlpt(E2, coord(r, 0), coord(r, 1)):
  136.     return = CreateAnimThumb(crv);
  137.  
  138. ###############################################################################
  139. #  Ratio bar widget
  140. ###############################################################################
  141.  
  142. RatioBar = FUNCTION(pt0, pt1, ratio): v: l: r:
  143.     v = pt0*(1.0-ratio) + pt1*ratio:
  144.     l = coerce(pt0, E2) + coerce(v, E2):
  145.     attrib(l, "dwidth", 5):
  146.     color(l, 7): # gray
  147.     r = coerce(v, E2) + coerce(pt1, E2):
  148.     attrib(r, "dwidth", 5):
  149.     color(r, yellow):
  150.     return = list(l, r);
  151.